<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./myaxios.js"></script>
</head>
<body>
    <button>发送</button>
    <button>取消</button>
    <script>
        let btns = document.querySelectorAll('button');
        let cancel = null;
        btns[0].onclick = function(){
            axios({
                method:'get',
                url: 'http://localhost:8000/timeout',
                headers:{
                    x:1,
                    y:2
                },
                cancelToken:new axios.CancelToken(c=>{
                    cancel = c;
                })
            }).then(value=>{
                console.log('value',value);
            })
        }

        btns[1].onclick = function(){
            cancel();
        }
    </script>
</body>
</html>